package ru.evga.gwt.lib.common.client.ui.dialog;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ConfirmDialog extends AbstractDialog implements ConfirmButtonBar.Presenter
{
    
    public interface IConfirmDialogHandler
    {
        void onYes();
        void onNo();
        void onCancel();
    }
    
    public static abstract class AbstractConfirmDialogHandler implements IConfirmDialogHandler
    {

        public void onNo()
        {
        }

        public void onCancel()
        {
        }
    }
    
    
    
    public enum BUTTON_TYPE
    {
        YES_NO, YES_NO_CANCEL
    }
    
    private String m_strMessage = "";
    private BUTTON_TYPE m_type;
    private IConfirmDialogHandler m_handler;
    
    public ConfirmDialog(
            String message, 
            BUTTON_TYPE type, 
            IConfirmDialogHandler handler)
    {
        super(true);
        m_type = type;
        m_strMessage = message;
        m_handler = handler;
//        setContentHeight("50px");
        setContentWidth("200px");
    }

    public Widget createButtonBar()
    {
        ConfirmButtonBar bar = new ConfirmButtonBar(m_type);
        bar.setPresenter(this);
        return bar;

    }
    

    /**
     * Creates content
     */
    public IsWidget createContent()
    {
        Label label = new Label(m_strMessage);
        return label;
    }

    public void cancelClicked()
    {
        if(m_handler != null)
        {
            m_handler.onCancel();
        }
        close();
    }

    public void yesClick()
    {
        if(m_handler != null)
        {
            m_handler.onYes();
        }
        close();
    }

    public void noClick()
    {
        if(m_handler != null)
        {
            m_handler.onNo();
        }
        close();
    }
    


}
